package com.alita.redis.utils.dingding;


import com.alita.redis.utils.dingding.entity.DingtalkChatbotClient;
import com.alita.redis.utils.dingding.entity.Message;
import com.alita.redis.utils.dingding.entity.SendResult;
import com.alita.redis.utils.dingding.entity.TextMessage;
import org.springframework.cglib.core.CollectionUtils;

import java.util.List;


/**
 * 钉钉发送工具
 */
public class DingtalkUtil {

    //这里后期使用配置解决-不单一写死
    private static final String YAN_FA_JIAO_LIU_CHATBOT  = "https://oapi.dingtalk.com/robot/send?access_token=87cabdfad03f0e2ea03c721c354f45c9eede209e9eb5e5e5dd39d90578b96b97";

    private static DingtalkChatbotClient client = DingtalkChatbotClient.getInstance();

    public static SendResult sendDingMessage(String msg, List<String> mobiles) {
        TextMessage message = new TextMessage(msg);
        if (mobiles != null){
            message.setAtMobiles(mobiles);
        }
        return send(message);
    }

    /**
     * 只能发送文本类型
     * @param message
     * @return
     */
    public static SendResult sendMessage(String message) {
        return send(new TextMessage(message));
    }

    /**
     * 发送消息 - 支持发送所有钉钉消息类型
     * @param message
     * @author : pengmuhua
     * @return
     */
    public static SendResult sendMessage(Message message) {
        return client.send(YAN_FA_JIAO_LIU_CHATBOT, message);
    }

    /**
     * 发送消息 - 支持发送所有钉钉消息类型
     * @param message
     * @author : pengmuhua
     * @return
     */
    public static SendResult send(TextMessage message) {
        return client.send(YAN_FA_JIAO_LIU_CHATBOT, message);
    }
}

